package com.hyh.toyshopping.service.impl;

import com.hyh.toyshopping.mapper.CarMapper;
import com.hyh.toyshopping.model.Car;
import com.hyh.toyshopping.model.view.CarView;
import com.hyh.toyshopping.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.myshopping.service.Impl
 * @Author:hyhWTX
 * @ClassName:CarServiceImpl
 * @CreateTime:2022年-12月-10日 16:41
 * @Description: TODO (一句话描述以下该类的功能)
 */
@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;
    @Override
    public void addCar(Car car) {

        int num = carMapper.isExistByCar(car);
        if(num>0){
            //2.如果存在则数量更新
            carMapper.updateCarCount(car);
        }else{
            carMapper.addCar(car);
        }

    }

    @Override
    public Integer getCount(int user_id) {
        return carMapper.getCount(user_id);
    }

    @Override
    public List<CarView> getCarList(Integer user_id) {
        return carMapper.getCarList(user_id);
    }

    @Override
    public void updateCarCount(Car car) {
        carMapper.updateCarCountByCarId(car.getCar_id(),car.getCar_count());
        //获取更新后的合计
        //将合计返回
    }

    @Override
    public void deleteCar(int car_id) {
        carMapper.deleteCar(car_id);
    }

    @Override
    public List<CarView> getPayCarList(int[] car_ids) {
        return carMapper.getPayCarList(car_ids);
    }
}
